home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-2.iso / Files II / Prog / D-G / GrafSys2.0rel.sit / GrafSys 2.0 rel / GrafSys 2.0 source / GrafSysInterface.p < prev    next >
Encoding:
Text File  |  1993-08-26  |  3.8 KB  |  152 lines  |  [TEXT/PJMM]

  1. unit GrafSysInterface;
  2.  
  3. {this unit declares globals and procedures used to interface the GrafSys with geobench}
  4. { written 1993 by C. Franz }
  5.  
  6. interface
  7.  
  8. uses
  9.     Matrix, Transformations, OffscreenCore, GrafSysCore, GrafSysScreen, GrafSysObject, Resources, OffScreenGraphics, GrafSysC, GeoBenchUtility, threeDVision;
  10.  
  11. const
  12.     MaxPolyLayer = 100;
  13.  
  14. type
  15.     TPolygon3dObj = object(TSGenericObject3D)
  16.             procedure Draw;
  17.             override;
  18.             procedure Setz (z: extended);
  19.         end;
  20.  
  21. var
  22.     EyeVector: Vector4;
  23.     CurrentEyeTrafo: Matrix4;
  24.     useQD: Boolean;
  25.     theCoordSys: TSObject3D;
  26.     visibility3d: Boolean;
  27.  
  28. procedure InitGrafSysInterface;
  29. {initialize the interface routines }
  30.  
  31.  
  32. procedure SetCurrentEye (M: trafoMatrT);
  33. {Get GeoBench's Trafo Matrix and convert it to GrafSys Trafo Matrix,}
  34. {set the current eye trafo matrix to it }
  35.  
  36.  
  37. implementation
  38.  
  39. procedure InitGrafSysInterface;
  40.     begin
  41.         SetVector4(EyeVector, 0, 0, 0);
  42.         CurrentEyeTrafo := Identity;
  43.         theCoordSys := GetNewNamedObject('XYZ Coord');
  44.         failNil(Handle(theCoordSys));
  45.         theCoordSys.Reset;
  46.     end;
  47.  
  48. procedure SetCurrentEye (M: trafoMatrT);
  49.     var
  50.         i: integer;
  51.         j: integer;
  52.     begin
  53.         for i := 1 to 4 do
  54.             for j := 1 to 4 do
  55.                 CurrentEyeTrafo.M[i, j] := M[i, j];
  56.         CurrentEyeTrafo.identityFlag := FALSE; (* always!!! *)
  57.         if current3DPort <> nil then begin
  58.             current3DPort^.MasterTransform := CurrentEyeTrafo;
  59.             current3DPort^.versionsID := current3Dport^.versionsID + 1; (* changes increment. Indicate we must redraw  *)
  60.         end
  61.         else
  62.             DebugStr('Trying to set current eye trafo without having 3D window allocated.');
  63.     end;
  64.  
  65.  
  66. procedure TPolygon3dObj.Draw;
  67.     override;
  68.  
  69.     var
  70.         theQDPoly: PolyHandle;
  71.         firstX, firstY: integer;
  72.         lastX, lasty, currX, currY: integer;
  73.         currPoly: integer;
  74.         pointIndex: longint;
  75.         offset: integer;
  76.         buffer: integer;
  77.  
  78.     begin
  79.         self.Transform(false); (* transform if we need to. Now all points are ready to draw *)
  80. (* all points are accessed incrementally until we are done *)
  81. (* Remember, GragSys internal index is ZCNT, PolyCount is OCNT! *)
  82.  
  83.         currPoly := 1;
  84.         pointIndex := 0;
  85.         offset := 0;
  86.         buffer := -1; (* will be incremented to 0 right away *)
  87.         if numPoints = 0 then (* no points to be drawn *)
  88.             exit(Draw);
  89.  
  90.  
  91.         theQDPoly := OpenPoly; (* open a new polygon *)
  92.  
  93.     (* calculate point address in memory and access first point in buffer *)
  94.         if offset mod (MaxPointPerBuf + 1) = 0 then (* advance buffer 1 *)
  95.             begin
  96.             buffer := buffer + 1;
  97.             currentBuf := theBufs[buffer];
  98.             if currentBuf = nil then
  99.                 DebugStr('About to access nil buffer in TSGenericObject3D.Transform');
  100.             offset := 0;
  101.         end;
  102.         (* get the point *)
  103.         firstX := currentBuf^[offset].screenX;
  104.         firstY := currentBuf^[offset].screenY;
  105.         MoveTo(firstX, firstY);
  106.         offset := offset + 1;
  107.         pointIndex := pointIndex + 1;
  108.  
  109.         while pointIndex < numPoints do begin (* nur '<' wegen ZCNT compare OCNT *)
  110.         (* calculate point address in memory *)
  111.             if offset mod (MaxPointPerBuf + 1) = 0 then (* advance buffer 1 *)
  112.                 begin
  113.                 buffer := buffer + 1;
  114.                 currentBuf := theBufs[buffer];
  115.                 if currentBuf = nil then
  116.                     DebugStr('About to access nil buffer in TSGenericObject3D.Transform');
  117.                 offset := 0;
  118.             end;
  119.         (* get the point *)
  120.             LineTo(currentBuf^[offset].screenX, currentBuf^[offset].screenY);
  121.             offset := offset + 1;
  122.             pointIndex := pointIndex + 1;
  123.         end; (* while pointindex < polygon endpoint *)
  124.  
  125.         LineTo(firstX, firstY); (* back to first point *)
  126.         ClosePoly;
  127.     (* now draw it *)
  128.         if visibility3d then (* hidden line *)
  129.             FillPoly(theQDPoly, white);
  130.         FramePoly(theQDPoly);
  131.         KillPoly(theQDPoly);
  132.  
  133.     end; (* TPolygon3dObj.Draw *)
  134.  
  135. procedure TPolygon3dObj.SetZ (z: extended);
  136.  
  137.     var
  138.         i: longint;
  139.         x, y, dummy: real;
  140.         theErr: Boolean;
  141.  
  142.     begin
  143.         if numPoints < 1 then
  144.             exit(SetZ);
  145.         for i := 1 to numPoints do begin
  146.             GetPoint(i, x, y, dummy);
  147.             theErr := ChangePoint(i, x, y, z);
  148.         end;
  149.     end;
  150.  
  151.  
  152. end.